<template>
  <div style="line-height:20px">
    <el-table border ref="multipleTable"
              class="resultTable"
              :data="tableConfig.tableData.slice((tableConfig.currentPage-1)*tableConfig.pageSize,tableConfig.currentPage*tableConfig.pageSize)"
              @selection-change="handleSelectionChange">
      <el-table-column type="selection"> </el-table-column>
      <el-table-column label="会议记录ID">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="browseDetails(scope.row.minutesId)">
            {{ scope.row.minutesId}}
          </el-button>
        </template>
      </el-table-column>
      <el-table-column prop="minutesTitle" label="会议记录标题"> </el-table-column>
      <el-table-column prop="minutesTime" label="会议记录时间"> </el-table-column>
    </el-table>

    <div style="margin-top:20px;float:center">
      <el-pagination
        background
        layout="total,prev, pager, next"
        :total= tableConfig.tableData.length
        @current-change="handleCurrentChange"
        :page-size= tableConfig.pageSize >
      </el-pagination>
    </div>

    <!-- 浏览学生详细信息 -->
    <div>
      <ScanMinutes/>
    </div>
  </div>
</template>

<script>
  // 引入公共的bug，来做为中间传达的工具
  import Bus from '@/components/Bus/bus.js'
  // 查看会议记录组件
  import ScanMinutes from '@/views/page-admin-main/components/ScanMinutes';

  export default {
    components: {
      ScanMinutes,
    },
    data() {
      return {
        tableConfig: {
          // 设置每一页显示多少数据
          pageSize: 10,
          // 设置当前页
          currentPage: 1,
          // 区分点击不同支部
          branchNo: 0,
          // 存储表格所有数据
          tableData: [],
        },
      }
    },
    created: function () {
      // 用$on事件来接收参数
      Bus.$on('select', (data) => {
        console.log("getAllMinutes:::" + data);
        // 通过then方法获取promise对象
        this.getRequest("admin/getAllMinutes").then(res=>{
          // res为获得到的state里的数据
          this.tableConfig.tableData = [];
          for(var i = 0; i <res.length; i++){
            this.tableConfig.tableData.push(res[i]);
            //console.log(this.tableData);
          }
        })
      })

    },
    methods: {
      handleSelectionChange(val) {
        this.tableConfig.multipleSelection = val;
      },
      // 方法：获取用户点击的页面传给父组件partyAdmin/MainPage.vue
      handleCurrentChange(newPage) {
        this.tableConfig.currentPage = newPage;
      },
      // Get方法 返回一个Promise对象
      getRequest : async function(url) {
        //console.log('calling');
        let getAwait = ()=>{
          return new Promise(resolve => {
            this.$axios({
              method: "get",
              url: url,
            }).then((response) => {
              if (response.data['data'] != null) {
                resolve(response.data['data']);
              }
            })
          });
        }
        let result = await getAwait();
        //console.log(result);
        return result;
      },
      // 点击触发ScanStudent控件
      browseDetails(minutesId){
        Bus.$emit('minutesId', minutesId);
        Bus.$emit('scanMinutesFormVisible', true);
      },
    }
  }
</script>

<style>

</style>
